/**
 * @file vue-cli config
 */
const path = require('path');
const clientPath = path.resolve(process.cwd(), './src/client');
module.exports = {
  publicPath: './', // 基本路径
  outputDir: './dist/client/', // 输出文件目录
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      // 为生产环境修改配置...
      config.mode = 'production'
    } else {
      // 为开发环境修改配置...
      config.mode = 'development'
    }
    Object.assign(config, {
      entry: [
        path.resolve(clientPath, 'main.js')
      ],
      // 开发生产共同配置
      resolve: {
        alias: {
          '@': path.resolve(__dirname, './src/client'),
          '@c': path.resolve(__dirname, './src/components'),
          '@p': path.resolve(__dirname, './src/views')
        } // 别名配置
      }
    })
  },
  // webpack-dev-server 相关配置
  devServer: {
    overlay: {
      warnings: true,
      errors: true
    }, // 错误、警告在页面弹出
    proxy: {
      '/api': {
        target: 'http://localhost:9001/api',
        changeOrigin: true, // 允许websockets跨域
        // ws: true,
        pathRewrite: {
          '^/api': '/api'
        }
      }
    } // 代理转发配置，用于调试环境
  }
};